package com.pipeline;

import com.entity.TArticle;
import com.entity.TAuthor;
import com.service.ArticleService;
import com.service.AuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * Created by del on 16-5-1.
 */
@Component
public class MySQLPipeline implements Pipeline{

    @Autowired
    private ArticleService articleService;

    @Autowired
    private AuthorService authorService;

    public void process(ResultItems resultItems, Task task) {
        TArticle tArticle = resultItems.get("article");
        TAuthor tAuthor = resultItems.get("author");
        if (tArticle != null) {
            articleService.addOrUpdate(tArticle);
        }
        if (tAuthor != null) {
            authorService.addOrUpdate(tAuthor);
        }
    }
}
